package com.yfjin.gl.location

import android.graphics.BitmapFactory
import android.opengl.GLES20
import android.opengl.GLSurfaceView
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.yfjin.gl.R
import kotlinx.android.synthetic.main.activity_location.*
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class LocationDemoActivity : AppCompatActivity() {


    private var mTextureId: Int = -1

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_location)


        gl_surface.setEGLContextClientVersion(2)


        val bitmap = BitmapFactory.decodeResource(resources, R.drawable.demo1)
        val filter = ImageFilter(this)

        gl_surface.setRenderer(object : GLSurfaceView.Renderer {
            override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
                mTextureId = filter.init(bitmap)
            }

            override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
                GLES20.glViewport(0, 0, width, height)
            }

            override fun onDrawFrame(gl: GL10?) {
                Log.i("123123", "onDrawFrame:" + mTextureId)
                filter.drawFrame(mTextureId)
            }
        })
    }
}